<?php echo $this->partial('entry/search.phtml') ?>
<?php echo $this->partial('message.phtml',array('mgs' => Core_Util::getLatestMessage('entry_approve'))) ?>
<?php if($this->paginator->count()):?>
<div class="entries_control">
    <a href="javascript:void(0)" title="<?php echo $this->translate('GUIDE_APPROVE_SELECTED_ENTRIES');?>" id="btn_approve"><?php echo $this->translate('ACTION_APPROVE');?></a>
    <a href="javascript:void(0)" title="<?php echo $this->translate('GUIDE_REJECT_SELECTED_ENTRIES');?>" id="btn_reject"><?php echo $this->translate('ACTION_REJECT');?></a>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $("#btn_approve").click(function(){            
            var id_entries = $('.cbx_entry:checked').map(function(){
                return this.value;
            }).get().join(',');
            if(id_entries == ""){
                alert("<?php echo $this->translate('PLEASE_SELECT_ENTRIES_TO_APPROVE')?>");
                return false;
            } 
            location.href="<?php echo $this->url(array('action' => 'approvelist'));?>/id_entries/" + id_entries;
        });
        $("#btn_reject").click(function(){
            var id_entries = $('.cbx_entry:checked').map(function(){
                return this.value;
            }).get().join(',');
            if(id_entries == ""){
                alert("<?php echo $this->translate('PLEASE_SELECT_ENTRIES_TO_REJECT')?>");
                return false;
            } 
            if(confirm("<?php echo $this->translate('MSG_CONFIRM_REJECTS'); ?>")){
                location.href="<?php echo $this->url(array('action' => 'rejectlist'));?>/id_entries/" + id_entries;
            }
        });
        $("#list_entries").change(function(){
            if($(this).attr("checked") == 'checked')
            {
                $('.cbx_entry').attr('checked', 'checked');
            }
            else
            {
                $('.cbx_entry').removeAttr('checked');
            }
        });
    });
</script>
<table class="sm_tbl_classic" id="list_submission">
<thead>
	<tr>
        <th style="width: 20px;">
            <span class="check_all_entry"><input type="checkbox" name="list_entries" id="list_entries" value="1"></span>
		</th>
		<th style="width: 254px;">
			<span><?php echo $this->translate('TABLE_HEADER_SUBMISSION');?></span>
		</th>
		<th style="width: 136px;">
			<?php echo $this->partial('manage/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'time_uploaded',
					'sort_default'  => 'DESC'
				),
				'label' => 'TABLE_HEADER_SUBMISSION_DATE'
			)) ?>
		</th>
		<th>
			<?php echo $this->partial('manage/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'views',
					'sort_default'  => 'DESC'
				),
				'label' => 'TABLE_HEADER_VIEWS'
			)) ?>
		</th>
		<th>
			<?php echo $this->partial('manage/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'votes',
					'sort_default'  => 'DESC'
				),
				'label' => 'TABLE_HEADER_VOTES'
			)) ?>
		</th>
		<th>
			<?php echo $this->partial('manage/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'shares',
					'sort_default'  => 'DESC'
				),
				'label' => 'TABLE_HEADER_SHARES'
			)) ?>
		</th>
		<th>
			<?php echo $this->partial('manage/sortable_item_control.phtml',array(
				'column' => array(
					'sort_column'   => 'status',
					'sort_default'  => 'ASC'
				),
				'label' => 'TABLE_HEADER_STATUS'
			)) ?>
		</th>
		<th style="width:90px;">
			<span>Action</span>
		</th>
	</tr>
</thead>
<tbody>
	<?php foreach ($this->paginator->getCurrentItems() as $entry):?>
		<?php /* @var $entry Core_Model_Entry */ ?>
		<tr>
            <td class="check_entry">
                <input class="cbx_entry" type="checkbox" name="entry" id="entry_<?php echo $entry['id']?>" value="<?php echo $entry['id']?>">
            </td>
			<td>
				<p>
                    <a  href="<?php echo $this->urlKeepIdPage(array('controller' => 'entry','action' => 'detail', 'id_entry' => $entry->id));?>">
						<img src="<?php echo $entry->getThumbnailImageUrl();?>" class="thumb_image"/>
					</a>
				</p>
				<p>
					<a  href="<?php echo $this->urlKeepIdPage(array('controller' => 'entry','action' => 'detail', 'id_entry' => $entry->id));?>">
                        <?php echo $this->escape($entry->title) ?>
                    </a> <br />
                    by <?php echo $this->blankLink($entry->getUser()->link, $entry->getCandidateName()?$this->escape($entry->getCandidateName()):'n/a') ?>
				</p>
			</td>
            <td class="date"><?php echo $entry->getSubmitDate() ?></td>
			<td class="align_right"><?php echo $entry->views ?></td>
			<td class="align_right"><?php echo $entry->votes ?></td>
			<td class="align_right"><?php echo $entry->shares ?></td>
			<td><?php echo $this->translate($entry->getStatusLabel()) ?></td>
			<td>
				<?php
					$arrOptions = array();
					if( $entry->status == Core_Model_IEntry::STATUS_PENDING)
					{
						$arrOptions['approve']	= $this->translate('ACTION_APPROVE');
						$arrOptions['reject']	= $this->translate('ACTION_REJECT');
					}
					elseif( $entry->status == Core_Model_IEntry::STATUS_APPROVED)
					{
						$arrOptions['reject']	= $this->translate('ACTION_REJECT');
					}
					elseif( $entry->status == Core_Model_IEntry::STATUS_REJECT)
					{
						$arrOptions['approve']	= $this->translate('ACTION_APPROVE');
					}
					$arrOptions['export']		= $this->translate('ACTION_EXPORT');
					$arrOptions['edit']			= $this->translate('ACTION_EDIT');
//                    $arrOptions['delete']		= $this->translate('ACTION_DELETE');
					$arrDisable = array(); 
					if( empty($entry->votes) ) 
						$arrDisable[] = 'export';
					echo $this->formSelect('action','0',
						array(
							'onchange'	=> 'performAction.call(this,'.$entry->id.');',
							'disable'	=> $arrDisable
						),
						array_merge(
							array('0'			=> $this->translate('ACTION_LABEL')),
							$arrOptions
						)
					)
				?>
			</td>
		</tr>
	<?php endforeach;?>
</tbody>
</table>
<?php echo $this->paginationControl(
		$this->paginator,
		'Sliding',
		'manage/pagination_control.phtml',
		array(
			'param_page'    => PARAM_PAGE_NAME,
			'query'         => isset($_GET)?$_GET:array()
		)
	);
?>
<?php else:?>
<div class="sm_paginator_item_empty">
    <p>No item is available.</p>
</div>
<?php endif; ?>
<script>
jQuery("document").ready(function($){
	addTab("<?php echo Core_Util::escapeForJs2($this->contest->getTitle()) ?>", '<?php echo $this->url() ?>');
    canvasScrollTo(0,0);
});
function performAction(id)
{
	var view_state = '<?php echo $this->{Core_Util::VIEW_STATE_ENTRY}?>';
	setcookie('<?php echo Core_Util::VIEW_STATE_ENTRY;?>',view_state,(new Date()).getTime()+3600,'/');
	var action = this.value;
	switch (action)
	{
		case 'edit':
			location.href="<?php echo $this->url(array('action' => 'edit'));?>/id_entry/" + id;
			break;
//        case 'delete':
//            var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_DELETE')?>');
//			if (!ok) break;
//			location.href="<?php echo $this->url(array('action' => 'delete'));?>/id_entry/" + id;
//			break;
		case 'reject':
			var ok = confirm('<?php echo $this->translate('MSG_CONFIRM_REJECT')?>');
			if (!ok) break;
			location.href="<?php echo $this->url(array('action' => 'reject'));?>/id_entry/" + id;
			break;
		case 'approve':			
			location.href="<?php echo $this->url(array('action' => 'approve'));?>/id_entry/" + id;
			break;
		case 'export':
			location.href="<?php echo $this->url(array('action' => 'export-voters'));?>/id_entry/" + id;
			break;
	}
	this.selectedIndex = 0;
}
</script>
